import 'package:flutter/material.dart';
import 'package:flutter_base_widget/base/base.dart';

class DrawPathScreen extends BasePage {

  @override
  Widget rebuild(BuildContext context) {
    super.rebuild(context);
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        PhysicalShape(
          clipper: ShapeBorderClipper(
            shape: BeveledRectangleBorder(
              borderRadius: BorderRadius.only(topLeft: Radius.circular(50))
            )
          ),
          color: Colors.pinkAccent,
          clipBehavior: Clip.antiAlias,
          child: Container(
            height: 100,
            color: Colors.redAccent,
            padding: const EdgeInsets.all(10),
            child: Container(
              color: Colors.blue,
            ),
          ),
        ),

        ClipPath(
          clipper: MyShapBorderClipper(),
          child: Container(
            height: 200,
            width: 200,
            color: Colors.blue,
            alignment: Alignment.bottomCenter,
            child: Container(
              color: Colors.cyanAccent,
              padding: const EdgeInsets.all(20.0),
              child: Text("abc"),
            ),
          ),
        ),
      ],
    );
  }
}

class MyShapBorderClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    // TODO: implement getClip
    var path = new Path();
    path.lineTo(0, size.height);

    var fisrtEndPoint = Offset(30, size.height - 80);
    var fistControlPoint = Offset(size.width / 2, size.height - 20);
    path.quadraticBezierTo(fisrtEndPoint.dx, fisrtEndPoint.dy, fistControlPoint.dx, fistControlPoint.dy);

    path.lineTo(size.width / 2, size.height - 20);

    var fisrtEndPoint1 = Offset(size.width * 0.8, size.height + 30); // 控制点。
    var fistControlPoint1 = Offset(size.width, size.height - 50);    // 结束点。
    path.quadraticBezierTo(fisrtEndPoint1.dx, fisrtEndPoint1.dy, fistControlPoint1.dx, fistControlPoint1.dy);
    
    path.lineTo(size.width, 0);
    path.close();

    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    // TODO: implement shouldReclip
    return oldClipper.runtimeType == MyShapBorderClipper;
  }

}